home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_u_z / xlock_dv.zip / SOURCES.ZIP / PASSCOMP.C < prev    next >
C/C++ Source or Header  |  1992-09-01  |  2KB  |  96 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6.     This function returns a pointer to the passed-in user's 
  7.     encrypted password.
  8. */
  9. char *getpasswd(char *user,char *pwfile)
  10. {
  11. FILE *fp;
  12. char line[80];
  13. char name[80];
  14. char password[80];
  15. char *p=NULL;
  16. int count=0;
  17.  
  18. if ((fp=fopen(pwfile,"r")) == NULL)
  19.     {
  20.     printf("ERROR: Unable to open password file: \"%s\"",pwfile);
  21.     exit(-1);
  22.     }
  23. else
  24.     {
  25.     while (!feof(fp))
  26.         {
  27.         if (fgets(line,80,fp) != NULL)
  28.             {
  29.             p=line; 
  30.             count=0;
  31.             while ((*p != ':') && (*p != NULL))
  32.                 {p++ ; count++;}
  33.             strncpy(name,line,count);
  34.             name[count]=NULL;
  35.  
  36.             if (!strcmp(name,user))
  37.                 {    /* Our guy?    */
  38.                 p++;                /* skip :    */
  39.                 count=strlen(p)-1;
  40.  
  41.                 strncpy(password,p,count);
  42.                 password[count]=NULL;
  43.                 
  44.                 return(password);
  45.                 }
  46.  
  47. /*
  48.             printf("\tScanned N=\"%s\", PW=\"%s\" count=%d\n",name,password,count);
  49. */
  50.             }
  51.         }
  52.     }
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. /*
  61. ************************************************************************
  62. *
  63. *   Password encryption routine largely stolen from:
  64. *   NCSA Telpass - edit password files for NCSA Telnet.
  65. *   Tim Krauskopf 6/88
  66. ************************************************************************
  67. */
  68. /****************************************************************************/
  69. /* Scompass
  70. *  compute and check the encrypted password
  71. */
  72. char *Sencompass(char *cleartext,char *encrypt)
  73. {
  74.     int i,ck;
  75.     char *p,c,*en,*ps;
  76.  
  77.     ck=0;
  78.     en=encrypt;
  79.     p=cleartext;
  80.     ps=cleartext;
  81.     while(*p)                /* checksum the string */
  82.         ck+=*p++;
  83.     c=(char) ck;
  84.     for(i=0; i<10; i++) {
  85.         *en=(char) (((*ps ^ c)|32)&127);     /* XOR with checksum */
  86.         if(*ps)
  87.             ps++;
  88.         else
  89.             c++;        /* to hide length */
  90.         en++;
  91.       }
  92.     *en=0;
  93.  
  94. return(encrypt);
  95. }
  96.